<!--  授信审核 - 全部 -->
<template>
  <div>
    <ZgNewPage
      ref="page"
      :title="pageTitle"
      :showInlineBtn="false"
      :uniqueName="uniqueName"
      :pageOpt="pageOpt"
      :dataBtns="dataBtns"
      :extraBtns="extraBtns"
      :headers="headers"
      :conditions="conditions"
      :adminWidth="180"
      @search="onSearch"
      @filter="onFilter"
      @header="mergeHeader"
      @admin="toAdmin"
      @extra="toExtra"
    >
      <template slot="columns">
        <a-table-column
          v-for="(h,i) in headers"
          :key="`column${i}`"
          :width="h.width===0 ? 'auto' : h.width"
          align="center"
          :title="h.label">
          <template slot-scope="record">
            <template v-if="h.code === 'A'">
              <span style="color:#1890ff">{{ A[record[h.code]] }}</span>
            </template>
            <template v-else>{{ record[h.code] }}</template>
          </template>
        </a-table-column>
      </template>
      <template slot="add">
        <Add ref="add"></Add>
      </template>
      <template slot="thMode" slot-scope="scope">
        <a-row :gutter="10">
          <a-col :span="4" v-for="t in scope.list" :key="`thMode_${t.id}`">
            <a-card class="mb10">
              <div class="wfull h100 scroll">
                {{ t }}
              </div>
            </a-card>
          </a-col>
        </a-row>
      </template>
    </ZgNewPage>
  </div>
</template>
<script>
const list = [
    { value: '1', label: '1' },
    { value: '2', label: '2' },
    { value: '3', label: '3' }
]
export default {
    components: {
  },
  data () {
    return {
      pageTitle: '授信列表-待办',
      uniqueName: 'test',
      A: {
        '1': '待审核',
        '2': '申请撤销',
        '3': '申请调额',
        '4': '未审核'
      },
      pageOpt: {
        showConditionBtn: true,
        showHeaderConfig: true,
        showAttachBtn: true,
        showPageTitle: false
      },
      conditions: [
        { code: 'name', compType: '单行文本', label: '企业名称', defaultVal: '' },
        { code: 'code', compType: '单行文本', label: '证件号码', defaultVal: '' },
        { code: 'product', compType: '单行文本', label: '授信产品', defaultVal: '' },
        { code: 'num', compType: '单行文本', label: '申请额度', defaultVal: '' },
        { code: 'select', compType: '下拉选择', label: '流转状态', defaultVal: '', extra: { 下拉选项: list } },
        { code: 'select', compType: '下拉选择', label: '授信类型', defaultVal: '', extra: { 下拉选项: list } },
        { code: 'select', compType: '下拉选择', label: '审核人', defaultVal: '', extra: { 下拉选项: list } },
        { code: 'select', compType: '下拉选择', label: '审核时间', defaultVal: '', extra: { 下拉选项: list } }
      ],
      headers: [
        { code: 'A', label: '状态', isShow: true, sort: 0 },
        { code: 'B', label: '企业名称', isShow: true, sort: 0 },
        { code: 'C', label: '证件类型', isShow: true, sort: 0 },
        { code: 'D', label: '证件号码', isShow: true, sort: 0 },
        { code: 'E', label: '授信类型', isShow: true, sort: 0 },
        { code: 'F', label: '授信产品', isShow: true, sort: 0 },
        { code: 'G', label: '申请额度', isShow: true, sort: 0 },
        { code: 'H', label: '创建时间', isShow: true, sort: 0 },
        { code: 'I', label: '审核时间', isShow: true, sort: 0 },
        { code: 'J', label: '审核人', isShow: true, sort: 0 }
      ],
      dataBtns: [
        { key: 1, name: '详情', type: 'link', isShow: () => { return true } },
        { key: 2, name: '同意撤销', type: 'link', isShow: (row) => row.A === '2' }
      ],
      extraBtns: [
       { key: 1, name: '导出', icon: 'download', type: 'primary' }
      ]
    }
  },
  methods: {
    search () {
      this.$refs.page.search()
    },
    onSearch (param) {
      const diyHeaders = localStorage.getItem(this.currentUser.username + '_diyHeader_' + this.uniqueName)
      if (diyHeaders) {
        this.mergeHeader(JSON.parse(diyHeaders))
      }
      // 加载表头
      const list = [
        { key: '1', id: '1', A: '1', B: '测试企业-1', C: '统一社会', D: '91*********XF', E: '产品授信', F: '浦发银承贷款', G: '10.000.000', H: '2025-6-11', I: '', J: '李华', isUse: true },
        { key: '2', id: '2', A: '2', B: '测试企业-1', C: '统一社会', D: '91*********XF', E: '产品授信', F: '浦发银承贷款', G: '10.000.000', H: '2025-6-11', I: '2025-6-11', J: '李华', isUse: true },
        { key: '3', id: '3', A: '3', B: '测试企业-1', C: '统一社会', D: '91*********XF', E: '产品授信', F: '浦发银承贷款', G: '10.000.000', H: '2025-6-11', I: '2025-6-11', J: '李华', isUse: true },
        { key: '4', id: '4', A: '4', B: '测试企业-1', C: '统一社会', D: '91*********XF', E: '产品授信', F: '浦发银承贷款', G: '10.000.000', H: '2025-6-11', I: '', J: '李华', isUse: true }
      ]
      this.$refs.page.endSearch({
        total: list.length,
        list: list
      })
    },
    onFilter (f, param) {
    },
    toAdd () {
        this.$refs.add.open()
    },
    toAdmin (param) {
      if (param.key === 1) {
        alert('查看详情')
      } else if (param.key === 2) {
        alert('同意撤销')
      }
    },
    toExtra (opt) {
      if (opt.key === 1) {
        alert('导出')
      }
    },
    mergeHeader (newHeaders) {
      if (!newHeaders) {
        return
      }
      this.headers = newHeaders.filter(t => {
        return t.isShow
      }).sort((a, b) => {
        return a.sort - b.sort
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
